package com.six.firstpage.controller;

import com.six.core.entity.Article;
import com.six.firstpage.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 15:53
 * @Description:
 */
@Api(value = "/firstpage/aritcle", tags = {"链接文章后端接口"})
@RestController
@RequestMapping("/firstpage/aritcle")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getArticle")
    public List<Article> getArticle(){
       return articleService.getAllArticle();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Article", name = "article", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addArticle")
    public Integer addArticle(@RequestBody Article article){
        return articleService.addArticle(article);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Article", name = "article", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateArticle")
    public Integer updateArticle(@RequestBody Article article){
        return articleService.updateArticle(article);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delArticle/{id}")
    public Integer delArticle(@PathVariable Integer id){
        return articleService.delArticle(id);
    }

}
